//
// Created by lenovo on 2024/7/1.
//

#ifndef TEYVATSURVIVAL_GAMEOBJ_GAMEOBJ_H
#define TEYVATSURVIVAL_GAMEOBJ_GAMEOBJ_H
#include "../../lang.h"
#include "../../Graphic/Graphic.h"
#include "../../Physics/Collision/Collision.h"
#include <vector>
using namespace std;
using namespace Game;
using namespace Graphic ;
using namespace Phy::Collision;
namespace Game::Obj{
    interface GameObj{
    public:
        virtual ~GameObj() = default ;
        virtual void onCollision(GameObj* other) = 0 ;
    };



    class Player ;
    class Bullet ;
    class Enemy ;
    class Item ;
//    class ColliderManager ;
    class CollisionManager ;//用于统一管理所有Obj的信息


    /**
     * @note
     * 尽量让collider与图像中心重合
     * @param
     * 问就是调的...
     */
    class Player : public GameObj{
    public:
        Graphic::Animation *anima ;
        Phy::Collision::AABB *collider{};
        Vector2f position ;
        Vector2f scale ;
        float speed ;
//        float _rate ;

        Player() ;
        ~Player() ;
        //getters
        Graphic::Animation *getAnimation() {return anima ;}
        Phy::Collision::AABB *getCollider() {return collider ;}
        Vector2f getPosition() {return position ;}
        Vector2f getScale() {return scale ;}
        float getSpeed() {return speed ;}

        void handleInput();
        void update(float delta) ;
        void onCollision (GameObj* other) override;
        void draw(sf::RenderWindow& window);
        void setPosition (Vector2f position) ;
        void setScale(Vector2f scale);
        void adjustCollider () ;
    };

    class Bullet : public GameObj{
    public:
        Bullet() ;//实现见源文件

        void onCollision (GameObj* other) override;
        void update(float deltaTime);
        void draw(sf::RenderWindow& window) ;

        // Getter for position
        sf::Vector2f getPosition() const {
            return position;
        }

        // Setter for position
        void setPosition(const sf::Vector2f& newPosition);

        // Getter for scale
        sf::Vector2f getScale() const {
            return scale;
        }

        // Setter for scale
        void setScale(const sf::Vector2f& newScale) {
            scale = newScale;
            shape->setScale(newScale);
        }

        void destroy() ;

    public:
        CircleCollider* collider ;
        sf::Vector2f position;
        sf::Vector2f scale;
        //shape后续可能需要用享元模式
        sf::CircleShape* shape;
    };

    class Enemy : public GameObj{
    public:
        Graphic::Animation *animaR ;
        Graphic::Animation *animaL ;
        Phy::Collision::CircleCollider *collider{};
        Vector2f position ;
        Vector2f scale ;
        float speed ;
        Vector2f direction ;
        Player* target;

        //getters
        Vector2f getPosition() const {
            return position;
        }

        Vector2f getScale() const {
            return scale;
        }

        float getSpeed() const {
            return speed;
        }

        Vector2f getDirection() const {
            return direction;
        }

        float getRadius() const {
            return scale.x * (float)(35.0/120.0);
        }



        void onCollision(GameObj* obj) override ;
        Enemy(Player* target);
        void update(float delta);
        void draw(sf::RenderWindow& window);
        void setPosition(Vector2f newPosition);
        void setScale(Vector2f newScale);
        void updateDirection();
        void adjustCollider () ;
        void destroy() ;
    };


};


#endif //TEYVATSURVIVAL_GAMEOBJ_GAMEOBJ_H
